<?php
/**
 ***** 扶摇而上、抱守本真 ******
 * @author Dana
 * @Date 2021/7/9
 */

class Depth{

    protected $res;

    public function __construct()
    {
        $this->res = 0;
    }

    public function max_depth($root,$dept = 1)
    {

        if(!$root){
            return $this->res;
        }

        if(!$root->left && !$root->right){
            $this->res = max($this->res,$dept);
        }

        $this->max_depth($root->left,$dept +1);
        $this->max_depth($root->right,$dept +1);
        
        return $this->res;

    }

    public function maxDepth($root)
    {
        return $root == null ? 0 : max($this->maxDepth($root->left),$this->maxDepth($root->right)) + 1;
    }
}